
#include "SoomlaIAP.h"

#include "CCVirtualCurrency.h"
#include "CCVirtualCurrencyPack.h"
#include "CCVirtualGood.h"
#include "CCSingleUseVG.h"
#include "CCPurchaseWithMarket.h"
#include "CCPurchaseWithVirtualItem.h"
#include "CCVirtualCategory.h"
#include "CCUpgradeVG.h"
#include "CCSingleUsePackVG.h"
#include "CCEquippableVG.h"

USING_NS_CC;
using namespace soomla;

#define kFullVersionEasy "android.test.purchased"
#define kFullVersionNormal "android.test.purchased"
#define kFullVersionHard "android.test.purchased"

SoomlaIAP *SoomlaIAP::create() {
	SoomlaIAP *ret = new SoomlaIAP();
    ret->autorelease();
    ret->init();

    return ret;
}

bool SoomlaIAP::init() {
    /** Google MANAGED Items **/
    CCVirtualGood *easyGood = CCLifetimeVG::create(
              __String::create("Full version: Easy mode"),
              __String::create("Test purchase for full version: easy mode!"),
              __String::create("iap_easy"),
              CCPurchaseWithMarket::createWithMarketItem(CCMarketItem::create(
                            __String::create(kFullVersionEasy),
                            __Integer::create(CCMarketItem::CONSUMABLE), CCDouble::create(0.99))
              )
    );
    CCVirtualGood *normalGood = CCLifetimeVG::create(
                  __String::create("Full version: Normal mode"),
                  __String::create("Test purchase for full version: normal mode!"),
                  __String::create("iap_normal"),
                  CCPurchaseWithMarket::createWithMarketItem(CCMarketItem::create(
                                __String::create(kFullVersionNormal),
                                __Integer::create(CCMarketItem::CONSUMABLE), CCDouble::create(1.99))
                  )
        );

    CCVirtualGood *hardGood = CCLifetimeVG::create(
                  __String::create("Full version: Hard mor"),
                  __String::create("Test purchase for full version: hard mode!"),
                  __String::create("iap_hard"),
                  CCPurchaseWithMarket::createWithMarketItem(CCMarketItem::create(
                                __String::create(kFullVersionHard),
                                __Integer::create(CCMarketItem::CONSUMABLE), CCDouble::create(2.99))
                  )
        );

    mCurrencies = __Array::create();
    mCurrencies->retain();

    mGoods = __Array::create(easyGood, normalGood, hardGood, NULL);
    mGoods->retain();

    mCurrencyPacks = __Array::create();
    mCurrencyPacks->retain();

    mCategories = __Array::create();
    mCategories->retain();

    return true;
}

SoomlaIAP::~SoomlaIAP() {
    CC_SAFE_RELEASE(mCurrencies);
    CC_SAFE_RELEASE(mGoods);
    CC_SAFE_RELEASE(mCurrencyPacks);
    CC_SAFE_RELEASE(mCategories);
}

int SoomlaIAP::getVersion() {
    return 0;
}

cocos2d::__Array *SoomlaIAP::getCurrencies() {
    return mCurrencies;
}

cocos2d::__Array *SoomlaIAP::getGoods() {
    return mGoods;
}

cocos2d::__Array *SoomlaIAP::getCurrencyPacks() {
    return mCurrencyPacks;
}

cocos2d::__Array *SoomlaIAP::getCategories() {
    return mCategories;
}

